/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI_SIFACT;

import AccesoDatosAvanzado.AD_Clientes;
import AccesoDatosSimple.cClientes;
import GUI_Busquedas.Frm_busq_clientes;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import sifact.conexion.cConexion;

/**
 *
 * @author joselugb
 */
public class Frm_Clientes extends javax.swing.JFrame {

    private String txtnulos = "Los Campos Vacios son:\n";

    /**
     * Creates new form Frm_Clientes
     */
    public Frm_Clientes() {
        setDefaultLookAndFeelDecorated(true);
        this.addFocusListener(null);
        initComponents();
    }
    //funcion para limpiar los campos

    private void CamposClean() {
        jTextFieldCodigo.setText(null);
        jTextFieldCedula.setText(null);
        jTextFieldNombres.setText(null);
        jTextFieldApellidos.setText(null);
        jTextFieldTlfno.setText(null);
        jTextAreaDireccion.setText(null);
    }
//funcion para bloquear campos cuando es Insercion

    private void CamposInsert() {
        //texto
        jTextFieldCedula.setEnabled(true);
        jTextFieldNombres.setEnabled(true);
        jTextFieldApellidos.setEnabled(true);
        jTextFieldTlfno.setEnabled(true);
        jTextAreaDireccion.setEnabled(true);
        //botones
        jButtonBuscar.setEnabled(false);
        jButtonAceptar.setEnabled(true);
    }
//funcion para bloquear campos cuando es Actualizacion

    private void CamposUpdate() {
        //texto
        jTextFieldCedula.setEnabled(false);
        jTextFieldNombres.setEnabled(true);
        jTextFieldApellidos.setEnabled(true);
        jTextFieldTlfno.setEnabled(true);
        jTextAreaDireccion.setEnabled(true);
        //botones
        jButtonBuscar.setEnabled(true);
        jButtonAceptar.setEnabled(false);
    }
//funcion para bloquear campos cuando es Eliminacion

    private void CamposDelete() {
        //texto
        jTextFieldCedula.setEnabled(false);
        jTextFieldNombres.setEnabled(false);
        jTextFieldApellidos.setEnabled(false);
        jTextFieldTlfno.setEnabled(false);
        jTextAreaDireccion.setEnabled(false);
        //botones
        jButtonBuscar.setEnabled(true);
        jButtonAceptar.setEnabled(false);
    }
//funcion que me permite verificar los campos nulos del formulario

    private boolean CamposNulos() {
        boolean band = false;
//        if (jTextFieldCodigo.getText().trim().equals(""))
//        {   txtnulos = txtnulos + "CODIGO\n"; band = true;  }
        if (jTextFieldCedula.getText().trim().equals("")) {
            txtnulos = txtnulos + "CEDULA\n";
            band = true;
        }
        if (jTextFieldNombres.getText().trim().toUpperCase().equals("")) {
            txtnulos = txtnulos + "NOMBRES\n";
            band = true;
        }
        if (jTextFieldApellidos.getText().trim().toUpperCase().equals("")) {
            txtnulos = txtnulos + "APELLIDOS\n";
            band = true;
        }
        if (jTextAreaDireccion.getText().trim().equals("")) {
            txtnulos = txtnulos + "DIRECCION\n";
            band = true;
        }

        return band;
    }
//Set de los datos establecidos para el cliente

    private void DatosFormulario(cClientes obj) {
//        obj.setNumIDCliente(Integer.parseInt(jTextFieldCodigo.getText().toString()));
        obj.setTxtCI(jTextFieldCedula.getText());
        obj.setTxtNombre(jTextFieldNombres.getText().toUpperCase());
        obj.setTxtApellido(jTextFieldApellidos.getText().toUpperCase());
        obj.setTxtDireccion(jTextAreaDireccion.getText().toUpperCase());
        obj.setTxtNumTlfno(jTextFieldTlfno.getText());
    }
//Asigno los datos devueltos en una busqueda    

    private void DatosFormularioBusqueda(String objcli) throws Exception {
        String[] tupla = new String[10];
        tupla = AD_Clientes.BuscarCI(objcli);

        jTextFieldCodigo.setText(tupla[0]);
        jTextFieldCedula.setText(tupla[1]);
        jTextFieldNombres.setText(tupla[2]);
        jTextFieldApellidos.setText(tupla[3]);
        jTextAreaDireccion.setText(tupla[4]);
        jTextFieldTlfno.setText(tupla[5]);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupClientes = new javax.swing.ButtonGroup();
        jPanelOpciones = new javax.swing.JPanel();
        jRadioButtonInsert = new javax.swing.JRadioButton();
        jRadioButtonUpdate = new javax.swing.JRadioButton();
        jRadioButtonDelete = new javax.swing.JRadioButton();
        jButtonBuscar = new javax.swing.JButton();
        jTabbedPaneDatosCliente = new javax.swing.JTabbedPane();
        jPanelDatosCliente = new javax.swing.JPanel();
        jLabelCodigo = new javax.swing.JLabel();
        jTextFieldCodigo = new javax.swing.JTextField();
        jLabelCI = new javax.swing.JLabel();
        jLabelNombres = new javax.swing.JLabel();
        jLabelApellidos = new javax.swing.JLabel();
        jLabelTlfno = new javax.swing.JLabel();
        jLabelDireccion = new javax.swing.JLabel();
        jTextFieldCedula = new javax.swing.JTextField();
        jTextFieldNombres = new javax.swing.JTextField();
        jTextFieldApellidos = new javax.swing.JTextField();
        jTextFieldTlfno = new javax.swing.JTextField();
        jScrollPaneDireccion = new javax.swing.JScrollPane();
        jTextAreaDireccion = new javax.swing.JTextArea();
        jLabelEjmTlfno = new javax.swing.JLabel();
        jLabelEjmCI = new javax.swing.JLabel();
        jPanelBotones = new javax.swing.JPanel();
        jButtonAceptar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("DATOS DEL CLIENTE");
        setResizable(false);

        jPanelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OPCIONES DEL CLIENTE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 18))); // NOI18N

        buttonGroupClientes.add(jRadioButtonInsert);
        jRadioButtonInsert.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonInsert.setText("AGREGAR");
        jRadioButtonInsert.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonInsertMouseClicked(evt);
            }
        });

        buttonGroupClientes.add(jRadioButtonUpdate);
        jRadioButtonUpdate.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonUpdate.setText("MODIFICAR");
        jRadioButtonUpdate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonUpdateMouseClicked(evt);
            }
        });

        buttonGroupClientes.add(jRadioButtonDelete);
        jRadioButtonDelete.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonDelete.setText("ELIMINAR");
        jRadioButtonDelete.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonDeleteMouseClicked(evt);
            }
        });

        jButtonBuscar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/16Nuvola_search_person.png"))); // NOI18N
        jButtonBuscar.setText("BUSCAR");
        jButtonBuscar.setEnabled(false);
        jButtonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelOpcionesLayout = new javax.swing.GroupLayout(jPanelOpciones);
        jPanelOpciones.setLayout(jPanelOpcionesLayout);
        jPanelOpcionesLayout.setHorizontalGroup(
            jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonBuscar)
                    .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                        .addComponent(jRadioButtonInsert)
                        .addGap(77, 77, 77)
                        .addComponent(jRadioButtonUpdate)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jRadioButtonDelete)
                .addContainerGap())
        );
        jPanelOpcionesLayout.setVerticalGroup(
            jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButtonInsert)
                    .addComponent(jRadioButtonUpdate)
                    .addComponent(jRadioButtonDelete))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonBuscar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPaneDatosCliente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jPanelDatosCliente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabelCodigo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelCodigo.setText("CODIGO:");

        jTextFieldCodigo.setEditable(false);
        jTextFieldCodigo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabelCI.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelCI.setText("CEDULA/RUC:");

        jLabelNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelNombres.setText("NOMBRES:");

        jLabelApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelApellidos.setText("APELLIDOS:");

        jLabelTlfno.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelTlfno.setText("TELEFONO:");

        jLabelDireccion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelDireccion.setText("DIRECCION:");

        jTextFieldCedula.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldCedulaKeyTyped(evt);
            }
        });

        jTextFieldNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldNombres.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jTextFieldNombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNombresKeyTyped(evt);
            }
        });

        jTextFieldApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldApellidos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldApellidosKeyTyped(evt);
            }
        });

        jTextFieldTlfno.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldTlfno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldTlfnoKeyTyped(evt);
            }
        });

        jTextAreaDireccion.setColumns(20);
        jTextAreaDireccion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextAreaDireccion.setRows(5);
        jScrollPaneDireccion.setViewportView(jTextAreaDireccion);

        jLabelEjmTlfno.setText("Ejm: 095632145");

        jLabelEjmCI.setText("Ejm: 1715632458001");

        javax.swing.GroupLayout jPanelDatosClienteLayout = new javax.swing.GroupLayout(jPanelDatosCliente);
        jPanelDatosCliente.setLayout(jPanelDatosClienteLayout);
        jPanelDatosClienteLayout.setHorizontalGroup(
            jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelCodigo)
                    .addComponent(jLabelCI)
                    .addComponent(jLabelNombres)
                    .addComponent(jLabelApellidos)
                    .addComponent(jLabelTlfno)
                    .addComponent(jLabelDireccion))
                .addGap(32, 32, 32)
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanelDatosClienteLayout.createSequentialGroup()
                        .addComponent(jTextFieldTlfno, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelEjmTlfno))
                    .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelDatosClienteLayout.createSequentialGroup()
                        .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jLabelEjmCI))
                    .addComponent(jTextFieldNombres)
                    .addComponent(jTextFieldApellidos)
                    .addComponent(jScrollPaneDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDatosClienteLayout.setVerticalGroup(
            jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCodigo)
                    .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCI)
                    .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEjmCI))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNombres)
                    .addComponent(jTextFieldNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelApellidos)
                    .addComponent(jTextFieldApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTlfno)
                    .addComponent(jTextFieldTlfno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEjmTlfno))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelDireccion)
                    .addComponent(jScrollPaneDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPaneDatosCliente.addTab("DATOS DEL CLIENTE", jPanelDatosCliente);

        jPanelBotones.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButtonAceptar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/16px-Crystal_Clear_action_apply.png"))); // NOI18N
        jButtonAceptar.setText("ACEPTAR");
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });

        jButtonCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/16px-Crystal_Clear_action_button_cancel.png"))); // NOI18N
        jButtonCancelar.setText("CANCELAR");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelBotonesLayout = new javax.swing.GroupLayout(jPanelBotones);
        jPanelBotones.setLayout(jPanelBotonesLayout);
        jPanelBotonesLayout.setHorizontalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addComponent(jButtonCancelar)
                .addContainerGap())
        );
        jPanelBotonesLayout.setVerticalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAceptar)
                    .addComponent(jButtonCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jTabbedPaneDatosCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 436, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jPanelOpciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(jPanelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelOpciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPaneDatosCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPaneDatosCliente.getAccessibleContext().setAccessibleName("DATOS DEL CLIENTE");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        try {
            // TODO add your handling code here:
            dispose();
            cConexion.cerrar();
        } catch (Exception ex) {
            Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jTextFieldNombresKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNombresKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldNombres.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldNombresKeyTyped

    private void jTextFieldApellidosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldApellidosKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldApellidos.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldApellidosKeyTyped

    private void jTextFieldCedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCedulaKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= '0' && t <= '9')) || jTextFieldCedula.getText().length() > 12) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldCedulaKeyTyped

    private void jTextFieldTlfnoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldTlfnoKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= '0' && t <= '9')) || jTextFieldTlfno.getText().length() > 8) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldTlfnoKeyTyped

    private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed

        //codigo para realizar las diferentes tareas Insert,Update,Delete
        Exception e;
        if (CamposNulos() == true) {//verifico que campo se encuentra vacio y advierto
            JOptionPane.showMessageDialog(null, txtnulos, "Campos Vacios", JOptionPane.INFORMATION_MESSAGE);
            txtnulos = "Los Campos Vacios son:\n";
        } else {//Inicio la Insercion
            if (jRadioButtonInsert.isSelected() == true) {                
                cClientes obj = new cClientes();
                DatosFormulario(obj);
                try {
                    e = AD_Clientes.Insertar(obj);
                    if (e == null) {
                        JOptionPane.showMessageDialog(null, "El CLIENTE ha sido ingresado correctamente", "INSERTAR", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL INSERTAR", JOptionPane.ERROR_MESSAGE);
                    }
                    dispose();
                    cConexion.cerrar();
                } catch (Exception ex) {
                    Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
                }
            }//Terminamos con la Insercion
            else {//Inicio de Actualizacion
                if (jRadioButtonUpdate.isSelected() == true) {                    
                    cClientes obj = new cClientes();
                    DatosFormulario(obj);
                    try {

                        e = AD_Clientes.Actualizar(obj);
                        if (e == null) {
                            JOptionPane.showMessageDialog(null, "Los datos se han actualizado correctamente", "MODIFICAR", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL MODIFICAR", JOptionPane.ERROR_MESSAGE);
                        }
                        dispose();
                        cConexion.cerrar();
                    } catch (Exception ex) {
                        Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }//terminanos con la Actualizacion
                else {//Iniciamos la Eliminacion
                    
                    cClientes obj = new cClientes();
                    DatosFormulario(obj);
                    try {

                        e = AD_Clientes.Eliminar(obj.getTxtCI());
                        if (e == null) {
                            JOptionPane.showMessageDialog(null, "Los datos se han Eliminado correctamente", "ELIMINAR", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL ELIMINAR", JOptionPane.ERROR_MESSAGE);
                        }
                        dispose();
                        cConexion.cerrar();
                    } catch (Exception ex) {
                        Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }//Terminamos la Eliminacion
            }
        }
    }//GEN-LAST:event_jButtonAceptarActionPerformed

    private void jRadioButtonInsertMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonInsertMouseClicked
        // TODO add your handling code here:
        CamposInsert();
        CamposClean();
        int e;
        try {
            e = AD_Clientes.GetId();
            e += 1;
            if (e >= 0) {
                jTextFieldCodigo.setText(Integer.toString(e));
            } else {
                JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL OBTENER CODIGO", JOptionPane.ERROR_MESSAGE);
            }
            cConexion.cerrar();
        } catch (Exception ex) {
            Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
        }




    }//GEN-LAST:event_jRadioButtonInsertMouseClicked

    private void jRadioButtonUpdateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonUpdateMouseClicked
        // TODO add your handling code here:
        CamposUpdate();
        CamposClean();
    }//GEN-LAST:event_jRadioButtonUpdateMouseClicked

    private void jRadioButtonDeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonDeleteMouseClicked
        // TODO add your handling code here:
        CamposDelete();
        CamposClean();
    }//GEN-LAST:event_jRadioButtonDeleteMouseClicked

    private void jButtonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarActionPerformed
        // TODO add your handling code here:
        if (jRadioButtonUpdate.isSelected() == true || jRadioButtonDelete.isSelected() == true) {
            String objcli = "";
            Frm_busq_clientes.setDefaultLookAndFeelDecorated(true);
            Frm_busq_clientes obj;
            try {
                obj = new Frm_busq_clientes(null, true, objcli);
                obj.setVisible(true);
                if (!obj.getObjcli().equals("")) {
                    DatosFormularioBusqueda(obj.getObjcli());
                }
                cConexion.cerrar();
            } catch (Exception ex) {
                Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
            }

//        DatosfrmBusq(obj.getObjcli());
            jButtonAceptar.setEnabled(true);
        }
    }//GEN-LAST:event_jButtonBuscarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
//        try {
////            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
////                if ("Nimbus".equals(info.getName())) {
////                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
////                    break;
////                }
////            }	   
//	    
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(Frm_Clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(Frm_Clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(Frm_Clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(Frm_Clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {                
                new Frm_Clientes().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupClientes;
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JButton jButtonBuscar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JLabel jLabelApellidos;
    private javax.swing.JLabel jLabelCI;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelDireccion;
    private javax.swing.JLabel jLabelEjmCI;
    private javax.swing.JLabel jLabelEjmTlfno;
    private javax.swing.JLabel jLabelNombres;
    private javax.swing.JLabel jLabelTlfno;
    private javax.swing.JPanel jPanelBotones;
    private javax.swing.JPanel jPanelDatosCliente;
    private javax.swing.JPanel jPanelOpciones;
    private javax.swing.JRadioButton jRadioButtonDelete;
    private javax.swing.JRadioButton jRadioButtonInsert;
    private javax.swing.JRadioButton jRadioButtonUpdate;
    private javax.swing.JScrollPane jScrollPaneDireccion;
    private javax.swing.JTabbedPane jTabbedPaneDatosCliente;
    private javax.swing.JTextArea jTextAreaDireccion;
    private javax.swing.JTextField jTextFieldApellidos;
    private javax.swing.JTextField jTextFieldCedula;
    private javax.swing.JTextField jTextFieldCodigo;
    private javax.swing.JTextField jTextFieldNombres;
    private javax.swing.JTextField jTextFieldTlfno;
    // End of variables declaration//GEN-END:variables
}
